home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / hack / 3_1_3 / sys / amiga / amilib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-10  |  7.3 KB  |  330 lines

  1. /*    SCCS Id: @(#)amilib.c    3.1    93/04/26    */
  2. /* Copyright (c) Gregg Wonderly, Naperville, Illinois,  1991,1992,1993. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #include "hack.h"
  6. #include "wintype.h"
  7. #include "winami.h"
  8. #include "func_tab.h"
  9.  
  10. #ifdef AMIGA_INTUITION
  11.  
  12. #include <exec/types.h>
  13. #include <graphics/gfxbase.h>
  14. #include <intuition/intuition.h>
  15. #include <intuition/intuitionbase.h>
  16. #include <libraries/dosextens.h>
  17. #include <ctype.h>
  18. #undef  strcmpi
  19. #include <string.h>
  20. #include <errno.h>
  21.  
  22. #ifdef  IDCMP_CLOSEWINDOW
  23. # define    INTUI_NEW_LOOK
  24. #endif
  25.  
  26. #ifdef AZTEC_C
  27. #include <functions.h>
  28. #else
  29. #include <dos.h>
  30. #include <proto/exec.h>
  31. #endif
  32.  
  33. #include "Amiga:lib/amilib.h"
  34.  
  35. #include "Amiga:winami.p"
  36. #include "Amiga:amiwind.p"
  37.  
  38. WinamiBASE *WinamiBase = 0;
  39.  
  40. extern char *roles[];
  41. extern char orgdir[];
  42.  
  43. struct Library *ConsoleDevice = 0;
  44. int bigscreen = 0;
  45. char Initialized = 0;
  46. struct amii_DisplayDesc *amiIDisplay = 0;
  47. struct Screen *HackScreen = 0;
  48. winid WIN_BASE = WIN_ERR;
  49. winid amii_rawprwin = WIN_ERR;
  50.  
  51. /*void genl_botl_flush( void );*/
  52. void amii_outrip( winid, int );
  53. void setup_librefs( WinamiBASE * );
  54.  
  55. /* The current color map */
  56. unsigned short amii_initmap[] = {
  57. #define C_BLACK        0
  58. #define C_WHITE        1
  59. #define C_BROWN        2
  60. #define C_CYAN        3
  61. #define C_GREEN        4
  62. #define C_MAGENTA    5
  63. #define C_BLUE        6
  64. #define C_RED        7
  65.  
  66.     0x0000, /* color #0 */
  67.     0x0FFF, /* color #1 */
  68.     0x0830, /* color #2 */
  69.     0x07ac, /* color #3 */
  70.     0x0181, /* color #4 */
  71.     0x0C06, /* color #5 */
  72.     0x023E, /* color #6 */
  73.     0x0c00  /* color #7 */
  74. };
  75.  
  76.  
  77.  
  78. /* Interface definition, for use by windows.c and winprocs.h to provide
  79.  * the simple intuition interface for the amiga...
  80.  */
  81. struct window_procs amii_procs =
  82. {
  83.     "amii",
  84.     amii_init_nhwindows,
  85.     amii_player_selection,
  86.     amii_askname,
  87.     amii_get_nh_event,
  88.     amii_exit_nhwindows,
  89.     amii_suspend_nhwindows,
  90.     amii_resume_nhwindows,
  91.     amii_create_nhwindow,
  92.     amii_clear_nhwindow,
  93.     amii_display_nhwindow,
  94.     amii_destroy_nhwindow,
  95.     amii_curs,
  96.     amii_putstr,
  97.     amii_display_file,
  98.     amii_start_menu,
  99.     amii_add_menu,
  100.     amii_end_menu,
  101.     amii_select_menu,
  102.     amii_update_inventory,
  103.     amii_mark_synch,
  104.     amii_wait_synch,
  105. #ifdef CLIPPING
  106.     amii_cliparound,
  107. #endif
  108.     amii_print_glyph,
  109.     amii_raw_print,
  110.     amii_raw_print_bold,
  111.     amii_nhgetch,
  112.     amii_nh_poskey,
  113.     amii_bell,
  114.     amii_doprev_message,
  115.     amii_yn_function,
  116.     amii_getlin,
  117. #ifdef COM_COMPL
  118.     amii_get_ext_cmd,
  119. #endif /* COM_COMPL */
  120.     amii_number_pad,
  121.     amii_delay_output,
  122.     /* other defs that really should go away (they're tty specific) */
  123. #ifdef CHANGE_COLOR
  124.     amii_delay_output,
  125.     amii_delay_output,
  126. #endif
  127.     amii_delay_output,
  128.     amii_delay_output,
  129.  
  130.     amii_outrip,
  131. };
  132.  
  133.  
  134. /* Interface definition, for use by windows.c and winprocs.h to provide
  135.  * the view window interface to nethack...
  136.  */
  137. struct window_procs amiv_procs =
  138. {
  139.     "amiv",
  140.     amii_init_nhwindows,
  141.     amii_player_selection,
  142.     amii_askname,
  143.     amii_get_nh_event,
  144.     amii_exit_nhwindows,
  145.     amii_suspend_nhwindows,
  146.     amii_resume_nhwindows,
  147.     amii_create_nhwindow,
  148.     amii_clear_nhwindow,
  149.     amii_display_nhwindow,
  150.     amii_destroy_nhwindow,
  151.     amii_curs,
  152.     amii_putstr,
  153.     amii_display_file,
  154.     amii_start_menu,
  155.     amii_add_menu,
  156.     amii_end_menu,
  157.     amii_select_menu,
  158.     amii_update_inventory,
  159.     amii_mark_synch,
  160.     amii_wait_synch,
  161. #ifdef CLIPPING
  162.     amii_cliparound,
  163. #endif
  164.     amii_print_glyph,
  165.     amii_raw_print,
  166.     amii_raw_print_bold,
  167.     amii_nhgetch,
  168.     amii_nh_poskey,
  169.     amii_bell,
  170.     amii_doprev_message,
  171.     amii_yn_function,
  172.     amii_getlin,
  173. #ifdef COM_COMPL
  174.     amii_get_ext_cmd,
  175. #endif /* COM_COMPL */
  176.     amii_number_pad,
  177.     amii_delay_output,
  178.     /* other defs that really should go away (they're tty specific) */
  179. #ifdef CHANGE_COLOR
  180.     amii_delay_output,
  181.     amii_delay_output,
  182. #endif
  183.     amii_delay_output,
  184.     amii_delay_output,
  185.  
  186.     amii_outrip,
  187. };
  188.  
  189. void
  190. amii_loadlib( void )
  191. {
  192.     /* Close the library if opened it already (switching display types) */
  193.     if( WinamiBase )
  194.     CloseLibrary( (struct Library *)WinamiBase );
  195.  
  196.     if( ( WinamiBase = ( WinamiBASE *)OpenLibrary( "winami.library", 0 ) ) == NULL )
  197.     {
  198.     panic( "can't find winami.library" );
  199.     }
  200.     setup_librefs( WinamiBase );
  201. }
  202.  
  203. void
  204. amiv_loadlib( void )
  205. {
  206.     /* Close the library if opened it already (switching display types) */
  207.     if( WinamiBase )
  208.     CloseLibrary( (struct Library *)WinamiBase );
  209.  
  210.     if( ( WinamiBase = ( WinamiBASE *)OpenLibrary( "winamiv.library", 0 ) ) == NULL )
  211.     {
  212.     panic( "can't find winami.library" );
  213.     }
  214.     setup_librefs( WinamiBase );
  215. }
  216.  
  217. void
  218. CleanUp()
  219. {
  220.     if( WinamiBase )
  221.     {
  222.     CloseLibrary( (struct Library *)WinamiBase );
  223.     WinamiBase = NULL;
  224.     }
  225. }
  226.  
  227. /* The library has references to the following code and data items in the main
  228.  * game, so fill in the access pointers for it to user...uggghhh...
  229.  */
  230. void
  231. setup_librefs( base )
  232.     WinamiBASE *base;
  233. {
  234.     base->G_pline = pline;
  235.     base->G_display_inventory = display_inventory;
  236.     base->G_terminate = terminate;
  237.     base->G_rnd = rnd;
  238.     base->G_panic = panic;
  239.     base->G_clearlocks = clearlocks;
  240.     base->G_on_level = on_level;
  241.     base->G_exit = exit;
  242.     base->G_lowc = lowc;
  243.     base->G_alloc = alloc;
  244.     base->G_Abort = Abort;
  245.     base->G_error = error;
  246.     base->G_fopenp = fopenp;
  247. /*    base->G_genl_botl_flush = genl_botl_flush; */
  248.  
  249.     base->G_yn_number = &yn_number;
  250.     base->G_zapcolors = zapcolors;
  251.     base->G_plname = plname;
  252.     base->G_objects = objects;
  253.     base->G_monsyms = monsyms;
  254.     base->G_extcmdlist = extcmdlist;
  255.     base->G_flags = &flags;
  256.     base->G_oc_syms = oc_syms;
  257.     base->G_showsyms = showsyms;
  258.     base->G_quitchars = quitchars;
  259.     base->G_pl_character = pl_character;
  260.     base->G_WIN_MESSAGE = &WIN_MESSAGE;
  261.     base->G_WIN_MAP = &WIN_MAP;
  262.     base->G_tc_gbl_data = &tc_gbl_data;
  263.     base->G_defsyms = defsyms;
  264.     base->G_WIN_STATUS = &WIN_STATUS;
  265.     base->G_u = &u;
  266.     base->G_roles = roles;
  267.     base->G_dungeon_topology = &dungeon_topology;
  268.     base->G_toplines = toplines;
  269.     base->G_WIN_INVEN = &WIN_INVEN;
  270.     base->G_windowprocs = &windowprocs;
  271.     base->G_orgdir = orgdir;
  272.     base->G_mons = mons;
  273.     base->G_amiIDisplay = &amiIDisplay;
  274.     base->G_HackScreen = &HackScreen;
  275.     base->G_pl_classes = pl_classes;
  276.     base->G_bigscreen = &bigscreen;
  277.     base->G_WINBASE = &WIN_BASE;
  278.     base->G_amii_rawprwin = &amii_rawprwin;
  279.     base->G_amii_initmap = amii_initmap;
  280.     base->G_Initialized = &Initialized;
  281.     base->G_ConsoleDevice = &ConsoleDevice;
  282.     base->G_amii_procs = &amii_procs;
  283. }
  284. #endif
  285.  
  286. void Abort(rc)
  287. long rc;
  288. {
  289. #ifdef CHDIR
  290.     chdir(orgdir);
  291. #endif
  292.     if (Initialized && ConsoleDevice) {
  293.     printf("\n\nAbort with alert code %08lx...\n", rc);
  294.     amii_getret();
  295.     } else
  296.     Alert(rc);
  297. #ifdef __SASC
  298.     {
  299. /*  __emit(0x4afc);     /* illegal instruction */
  300.     __emit(0x40fc);     /* divide by */
  301.     __emit(0x0000);     /*  #0  */
  302.     /* NOTE: don't move CleanUp() above here - */
  303.     /* it is too likely to kill the system     */
  304.     /* before it can get the SnapShot out, if  */
  305.     /* there is something really wrong.    */
  306.     }
  307. #endif
  308.     CleanUp();
  309. #undef exit
  310. #ifdef AZTEC_C
  311.     _abort();
  312. #endif
  313.     exit((int) rc);
  314. }
  315.  
  316. /* fatal error */
  317. /*VARARGS1*/
  318. void error VA_DECL(const char *, s)
  319.     VA_START(s);
  320.     VA_INIT(s, char *);
  321.  
  322.     putchar('\n');
  323.     vprintf(s, VA_ARGS);
  324.     putchar('\n');
  325.  
  326.     VA_END();
  327.     Abort(0L);
  328. }
  329.  
  330.